//
// Created by Dell on 2020/3/6.
//
#include <iostream>
using namespace std;

//执行后a升序排列，数组b为辅助数组
void merge(int *a, int *b, int p, int q, int r) {
    int s = p, t = q + 1, k = p;
    while (s <= q && t <= r) {
        if (a[s] <= a[t])
            b[k++] = a[s++];
        else
            b[k++] = a[t++];
    }
    if (s == q + 1)
        for (int i = t; i <= r; i++)
            b[k++] = a[i];
    else
        for (int i = s; i <= q; i++)
            b[k++] = a[i];
    for (int i = p; i <= r; i++)
        a[i] = b[i];
}

int main() {
    int a[8] = {1627, 1896,3147,3605,2957,3000,3592,3959};
    int b[8] = {0};

    merge(a, b, 0, 3, 7);

    for (int i : a)
        cout << i << " ";
}